//
//  ScanTurnOverFullCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/7/28.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "ScanTurnOverFullCell.h"

@interface ScanTurnOverFullCell ()

@end

@implementation ScanTurnOverFullCell

+ (instancetype)ScanTurnOverFullCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"ScanTurnOverFullCell";
    ScanTurnOverFullCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[ScanTurnOverFullCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

-(void)setBoxArray:(NSMutableArray<TurnOverBoxModel *> *)boxArray {
    _boxArray = boxArray;
    [self configUI];
}

- (void)configUI {
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    CGFloat btnW = (ScreenW - 30 - 10) * 0.5;
    CGFloat btnH = 42;
    CGFloat margin = 15;
    [self.boxArray enumerateObjectsUsingBlock:^(TurnOverBoxModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIButton *btn = [UIButton new];
        if (idx % 2 == 0) {
            btn.nim_left = margin;
        }else {
            btn.nim_left = margin * 2 + btnW;
        }
        btn.nim_top = (idx / 2) * 10 + btnH * (idx / 2);
        btn.nim_width = btnW;
        btn.nim_height = btnH;
        btn.backgroundColor = HexColor(0xF7F7FA);
        btn.layer.masksToBounds = YES;
        btn.layer.cornerRadius = 4;
        [btn setTitle:obj.boxNO forState:0];
        [btn setTitleColor:Color_ThemeColor forState:0];
        btn.titleLabel.font = BoldFontOfSize(14);
        [btn setImage:[UIImage imageNamed:@"icon_turnover_case"] forState:0];
        btn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
        [self.contentView addSubview:btn];
    }];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
